@extends('layouts.admin')
@section('content')

        <!--面包屑导航 开始-->
<div class="crumb_warp">
    <i class="fa fa-home"></i> <a href="{{url('admin/info')}}"> 首页</a> &raquo;  <a href="{{url('admin/category')}}">栏目管理</a>
</div>
<!--面包屑导航 结束-->



<!--搜索结果页面 列表 开始-->
<form action="#" method="post">
    <div class="result_wrap">
        <!--快捷导航 开始-->
        <div class="result_content">
            <!--快捷导航 开始-->
            <div class="result_content">
                <div class="short_wrap">
                    <a href="{{url('admin/category/create')}}"><i class="fa fa-plus"></i>新增栏目</a>
                    <a href="javascript:;" onclick="javascript:location.href=location.href"><i class="fa fa-refresh"></i>刷新</a>
                </div>
            </div>
            <!--快捷导航 结束-->
        </div>
        <!--快捷导航 结束-->
    </div>

    <div class="result_wrap">
        <div class="result_content">
            <table class="list_tab">
                <tr>
                    <th class="tc">排序</th>
                    <th class="tc">ID</th>
                    <th>栏目名称</th>
                    <th>栏目标题(描述)</th>
                    <th>栏目等级</th>
                    <th>查看次数</th>
                    <th>操作</th>
                </tr>
                @foreach($data as $v)
                <tr>
                    <td class="tc">
                        <input type="text" name="ord[]" onchange="changeOrder(this,{{$v->id}})" value="{{$v->orders}}">
                    </td>
                    <td class="tc">{{$v->id}}</td>
                    <td>
                        <a href="#">{{$v->_cate_name}}</a>
                    </td>
                    <td>{{$v->title}}</td>
                    <td>{{$v->level}}</td>
                    <td>{{$v->view}}</td>
                    <td>
                        <a href="{{url('admin/category/'.$v->id.'/edit')}}">修改</a>
                        <a href="javascript:;" onclick="delCate({{$v->id}})">删除</a>
                    </td>
                </tr>
                @endforeach
            </table>

        </div>
    </div>
</form>
<!--搜索结果页面 列表 结束-->
<script>
    function changeOrder(obj,cate_id){
        var cate_order=$(obj).val();
        $.post('{{url('admin/category/changeorder')}}',{'_token':'{{csrf_token()}}','id':cate_id,'orders':cate_order},function(data){
            if(typeof data=="object"){
                if(data.status==200){
                    layer.msg(data.msg, {icon: 6,time: 2000,shade: [0.8, '#393D49']});
                }else{
                    layer.msg(data.msg, {icon: 5,time: 2000,shade: [0.8, '#393D49']});
                }
            }else{
                layer.msg('没有权限', {icon: 5,time: 2000,shade: [0.8, '#393D49']});
            }
        });
    }

    //删除分类
    function delCate(cate_id) {
        layer.confirm('您确定要删除这个分类吗？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $.post("{{url('admin/category/')}}/"+cate_id,{'_method':'delete','_token':"{{csrf_token()}}"},function (data) {
                if(typeof data=="object"){
                    if(data.status==200){
                        layer.msg(data.msg, {icon: 6,time: 2000,shade: [0.8, '#393D49']});
                        location.href = location.href;
                    }else{
                        layer.msg(data.msg, {icon: 5,time: 2000,shade: [0.8, '#393D49']});
                    }
                }else{
                    layer.msg('没有权限', {icon: 5,time: 2000,shade: [0.8, '#393D49']});
                }
            });
        }, function(){

        });
    }
</script>
@endsection